package domain;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.NotBlank;

@Entity
@Access(AccessType.PROPERTY)

@Table( indexes = {@Index(columnList = "referenceNumber")} )
public class PurchasedItem extends DomainEntity{

	//Constructors
	public PurchasedItem(){
		super();
	}
	
	//Attributes

	private String referenceNumber;
	private String name;
	private String description;
	private String state;
	private Money price;
	private int purchasedUnits;
	
	
	@NotBlank
	@Pattern(regexp = "^(\\w+-\\w+)+$")
	public String getReferenceNumber() {
		return referenceNumber;
	}
	public void setReferenceNumber(String referenceNumber) {
		this.referenceNumber = referenceNumber;
	}
	
	@NotBlank
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@NotBlank
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@NotBlank
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
	@NotNull
	@Valid
	public Money getPrice() {
		return price;
	}
	public void setPrice(Money price) {
		this.price = price;
	}
	
	@Min(1)
	public int getPurchasedUnits() {
		return purchasedUnits;
	}
	public void setPurchasedUnits(int purchasedUnits) {
		this.purchasedUnits = purchasedUnits;
	}
	
	//Relationships
	
	private Order order;
	private Customer seller;
	
	@NotNull
	@Valid
	@ManyToOne(optional=false)
	public Order getOrder() {
		return order;
	}
	public void setOrder(Order order) {
		this.order = order;
	}
	
	@Valid
	@NotNull
	@ManyToOne(optional = false)
	public Customer getSeller() {
		return seller;
	}
	public void setSeller(Customer seller) {
		this.seller = seller;
	}

	
	
	
}
